local skel = fk.CreateSkill {
  name = "efengqi__longhun",
}

Fk:loadTranslationTable{
  ["efengqi__longhun"] = "龙魂",
  [":efengqi__longhun"] = "你可以将两张同花色的牌当游戏内存在该花色的基本牌使用。你使用的无花色牌带有《空巢：摸四张牌》。",

  ["#efengqi__longhun"] = "龙魂:将两张同花色的牌当游戏内存在该花色的基本牌使用",
  ["FQLongHun"] = "%arg[%arg2]",

  ["$efengqi__longhun1"] = "龙战于野，其血玄黄。",
  ["$efengqi__longhun2"] = "潜龙勿用，藏锋守拙。",
}

skel:addEffect("viewas", {
  prompt = "#efengqi__longhun",
  pattern = ".|.|.|.|.|basic",
  interaction = function(self, player)
    local tag = Fk:currentRoom():getBanner("FQLongHun")
    if tag == nil then return end
    local choices = {}
    for _, name in ipairs(Fk:getAllCardNames("b")) do
      local card = Fk:cloneCard(name)
      if ((Fk.currentResponsePattern == nil and player:canUse(card)) or
      (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card))) then
        if tag[name] then
          table.insert(choices, "FQLongHun:::" .. name.. ":" .. table.concat(table.map(tag[name], function (s)
            return Fk:translate(s, "zh_CN")
          end), ","))
        end
      end
    end
    if #choices == 0 then return end
    return UI.ComboBox { choices = choices }
  end,
  card_filter = function (self, player, to_select, selected)
    local name = self.interaction.data
    if name == nil or #selected > 1 then return false end
    name = string.split(name, ":")[4]
    local tag = Fk:currentRoom():getBanner("FQLongHun") or {}
    local card = Fk:getCardById(to_select)
    if tag[name] and table.contains(tag[name], card:getSuitString(true)) then
      return #selected == 0 or card.suit == Fk:getCardById(selected[1]).suit
    end
  end,
  view_as = function(self, _, cards)
    if #cards ~= 2 or not self.interaction.data then return nil end
    local c = Fk:cloneCard(string.split(self.interaction.data, ":")[4])
    c.skillName = self.name
    c:addSubcards(cards)
    return c
  end,
  enabled_at_play = function(self, player)
    return table.find(Fk:getAllCardNames("b"), function (name)
      return player:canUse(Fk:cloneCard(name))
    end)
  end,
  enabled_at_response = function (self, player, response)
    return not response and #player:getCardIds("he") > 1
  end,
})

skel:addEffect(fk.CardUsing, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and data.card.suit == Card.NoSuit and player:isKongcheng()
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:drawCards(4, skel.name)
  end,
})

skel:addAcquireEffect(function (self, player, is_start)
  local room = player.room
  if room:getBanner("FQLongHun") then return end
  local map = {}
  for _, id in ipairs(Fk:getAllCardIds()) do
    local card = Fk:getCardById(id, true)
    if card.type == Card.TypeBasic and not card.is_derived then
      map[card.name] = map[card.name] or {}
      table.insertIfNeed(map[card.name], card:getSuitString(true))
    end
  end
  room:setBanner("FQLongHun", map)
end)

return skel
